package com.andyage.admin.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.andyage.admin.bean.AdnewsBean;
import com.andyage.admin.bean.AdprojectapplyBean;
import com.andyage.admin.dao.AdnewsMapper;
import com.andyage.admin.dao.AdprojectApplyMapper;
import com.andyage.admin.service.IAdprojectApplyService;
import com.andyage.util.GetUUID;
import com.andyage.util.JsonContent;

import net.sf.json.JSONObject;
@Service
public class AdprojectApplyServiceImpl implements IAdprojectApplyService {
	@Resource
	private AdprojectApplyMapper projectApplyMapper;
	@Resource
	private AdnewsMapper adnewsMapper;
	@Override
	public String queryAdprojectApplyInfo(AdprojectapplyBean projectapply) throws Exception {
		List<AdprojectapplyBean> list = projectApplyMapper.queryAdprojectApplyInfo(projectapply);
		int total = projectApplyMapper.queryAdprojectApplyInfoCount(projectapply);
		String json=JsonContent.getJsonArray(list, total);
		return json;
	}

	@Override
	public String updateAdprojectApplyInfo(AdprojectapplyBean projectapply,HttpServletRequest request) throws Exception {
		AdnewsBean newsBean=new AdnewsBean();
		newsBean.setNewsId(GetUUID.get());
		//newsBean.setNewsPushId((String)request.getSession().getAttribute("adminId"));;
		newsBean.setNewsPushType(0);
		newsBean.setNewsReceiveId(projectapply.getPaUserId());
		newsBean.setNewsReceiveType(1);
		newsBean.setNewsStatus(0);
		newsBean.setNewsTime(new Date());
		System.out.println(projectapply.getPaStatus());
		System.out.println(projectapply.getPaUserId());
		if(projectapply.getPaStatus()==1){
			newsBean.setNewsDescription("审核通过");
		}
		if(projectapply.getPaStatus()==2){
			newsBean.setNewsDescription("审核未通过");
		}
		adnewsMapper.addNewsInfo(newsBean);
		int result=projectApplyMapper.updateAdprojectApplyInfo(projectapply);
		JSONObject json=new JSONObject();
		if(result>0){
			json.accumulate("result", 1);
			json.accumulate("tips", "修改成功");
		} else {
			json.accumulate("result", 0);
			json.accumulate("tips", "修改失败");
		}
		return json.toString();
	}

}
